using UnityEngine;
using System.Collections;

public class MProgress : MControl
{
    public float maxValue, value;
	
    float max;
    public void Start()
    {
        tx = view.width;
        ty = view.height;

        max = tx / 10;

        gameObject.transform.localScale = new Vector3(max, 1, ty / 10);

        x = sx + tx / 2 + x;
        y = sy - ty / 2 - y;
        gameObject.transform.position = new Vector3(x, y, -depth);


        gameObject.renderer.material.mainTexture = view;
        gameObject.renderer.material.mainTextureOffset = new Vector2(1, 1);
        gameObject.renderer.material.mainTextureScale = new Vector2(-1, -1);
    }

    public virtual void Update()
    {
        Vector3 vec = gameObject.transform.localScale;
        float _x = (value / maxValue) * max;
        gameObject.transform.localScale = new Vector3(_x, vec.y, vec.z);

        _x = (value / maxValue) * view.width;
        vec = gameObject.transform.position;
        gameObject.transform.position = new Vector3(x - (view.width - _x)/2, vec.y, vec.z);

    }
	
	public float Value
	{
		set { this.value = value; }
		get { return this.value; }
	}
	
	public float MaxValue
	{
		set { this.maxValue = value; }
		get { return this.maxValue; }
	}
}
